G+ = g++ 
C = gcc
#　头文件搜索路径
INC = -I ./include_u
# 所依赖的库
#opencv　 3.0所需要依赖的库：
#OPENCV_LIB = /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgcodecs.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_shape.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videoio.so /usr/local/lib/libopencv_videostab.so
#opencv　 2.0所需要依赖的库：
OPENCV_LIB = -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab
#user依赖的库
USER_LIB = -lpthread -lv4l2
#　指定g++参数
CFLAGS = -std=c++11
#　最终的可执行文件名
TARGET = ./output/test  

# 将源文件中所有的.c文件全部编译生成.O文件并放入./output目录中
./output/%.o:./src/%.c ./include_u
	$(C) $(INC) $(CFLAGS) -c $< -o $@

#　将源文件中所有的.cpp文件全部编译生成.O文件并放入./output目录中
./output/%.o:./src/%.cpp ./include_u
	$(G+) $(INC) $(CFLAGS) -c $< -o $@
 

# 展开源文件目录下的所有的.cpp文件，并将其存放于SOURCES中
SOURCES = $(wildcard ./src/*.cpp ./src/*.c) 
# 去除SOURCES中的路径存放于SOURCES_NDIR中
SOURCES_NDIR=$(notdir $(SOURCES))
# 替换,得到./output/*.o的集合　  
OBJS = $(patsubst %.c,./output/%.o,$(patsubst %.cpp,./output/%.o,$(SOURCES_NDIR)))

$(TARGET):$(OBJS)  
	$(G+) $(OBJS) $(OPENCV_LIB) $(USER_LIB) -o $(TARGET)
	chmod a+x $(TARGET) 
	@echo $(SOURCES)
  
clean:  
	rm -rf ./output/*.o $(TARGET)
